<style>
.app-main{
  background: #f5f9ff;
}
p{
  font-size: 15px;
  padding-top: 15px;
}

.a{
 width: 1600px;
  height: 1000px;
}

</style>
<template>
  <div class="app-container" style="margin: auto; margin-top: 20px; border-radius:5px; width: 80%; height: 700px; background: #FFFFFF">
    <el-dialog title="对账单结算" :visible.sync="dialogVisible" width="30%" :before-close="handleClose" class="a">
      <div></div>
      <p>应收单号：{{form.reconciliationNo}}</p>
      <p>客户：{{form.customer}}</p>
      <p>应收合计：{{form.totalReceivableAmount}}</p>
      <el-form ref="form" :model="form">
        <el-form-item label="实收合计" prop="reconciliationNo" class="z">
          <el-input v-model="tota" placeholder="请输入实收合计" />
        </el-form-item>

        <el-form-item label="备注" class="z">
          <el-input type="textarea"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取消</el-button>
    <el-button type="primary" @click="bao">保存</el-button>
  </span>
    </el-dialog>

    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-button type="primary" plain @click="jie">结算</el-button>
      <el-button plain>导入</el-button>
      <el-button plain @click="handleExport">导出</el-button>
      <el-button @click="handlePrint" plain>打印</el-button>
      <br><br>
      <el-form-item label="结算状态">
        <el-select v-model="queryParams.settlementStatus" placeholder="请选择" clearable>
          <el-option label="全部" value="全部"></el-option>
          <el-option label="未结算" value="未结算"></el-option>
          <el-option label="部分完成" value="部分完成"></el-option>
          <el-option label="结算完成" value="结算完成"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="daterangeCreatedTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

<!--    <el-row :gutter="10" class="mb8">-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['ysdz:ysdz:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['ysdz:ysdz:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['ysdz:ysdz:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['ysdz:ysdz:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
<!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
<!--    </el-row>-->

    <el-table v-loading="loading" :data="ysdzList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="id" />
      <el-table-column label="对账单号" align="center" prop="reconciliationNo" />
      <el-table-column label="客户" align="center" prop="customer"/>
      <el-table-column label="结算状态" align="center" prop="settlementStatus">
        <template slot-scope="scope">
            {{scope.row.settlementStatus==0?'未结算':'已结算'}}
        </template>
      </el-table-column>
      <el-table-column label="订单总数量" align="center" prop="totalOrderQuantity" />
      <el-table-column label="货物数量" align="center" prop="totalGoodsQuantity" />
      <el-table-column label="货物总体积" align="center" prop="totalGoodsVolume" />
      <el-table-column label="货物总重量" align="center" prop="totalGoodsWeight" />
      <el-table-column label="应收总金额(元)" align="center" prop="totalReceivableAmount" />
      <el-table-column label="实收总金额(元)" align="center" prop="totalReceivedAmount" />
      <el-table-column label="创建人" align="center" prop="createdBy" />
      <el-table-column label="创建时间" align="center" prop="createdTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="tiao"
            v-hasPermi="['ysdz:ysdz:edit']"
          >详情</el-button>
<!--          handleUpdate(scope.row)-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改应收对账单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="对账单号" prop="reconciliationNo">
          <el-input v-model="form.reconciliationNo" placeholder="请输入对账单号" />
        </el-form-item>
        <el-form-item label="客户" prop="customer">
          <el-input v-model="form.customer" placeholder="请输入客户" />
        </el-form-item>
        <el-form-item label="订单总数量" prop="totalOrderQuantity">
          <el-input v-model="form.totalOrderQuantity" placeholder="请输入订单总数量" />
        </el-form-item>
        <el-form-item label="货物数量" prop="totalGoodsQuantity">
          <el-input v-model="form.totalGoodsQuantity" placeholder="请输入货物数量" />
        </el-form-item>
        <el-form-item label="货物总体积" prop="totalGoodsVolume">
          <el-input v-model="form.totalGoodsVolume" placeholder="请输入货物总体积" />
        </el-form-item>
        <el-form-item label="货物总重量" prop="totalGoodsWeight">
          <el-input v-model="form.totalGoodsWeight" placeholder="请输入货物总重量" />
        </el-form-item>
        <el-form-item label="应收总金额(元)" prop="totalReceivableAmount">
          <el-input v-model="form.totalReceivableAmount" placeholder="请输入应收总金额(元)" />
        </el-form-item>
        <el-form-item label="实收总金额(元)" prop="totalReceivedAmount">
          <el-input v-model="form.totalReceivedAmount" placeholder="请输入实收总金额(元)" />
        </el-form-item>
        <el-form-item label="创建人" prop="createdBy">
          <el-input v-model="form.createdBy" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createdTime">
          <el-date-picker clearable
            v-model="form.createdTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listYsdz, getYsdz, delYsdz, addYsdz, updateYsdz } from "@/api/ysdz/ysdz";

export default {
  name: "Ysdz",
  data() {
    return {
      tota:null,
      dialogVisible: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 应收对账单表格数据
      ysdzList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 创建时间时间范围
      daterangeCreatedTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        settlementStatus: null,
        createdTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询应收对账单列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreatedTime && '' != this.daterangeCreatedTime) {
        this.queryParams.params["beginCreatedTime"] = this.daterangeCreatedTime[0];
        this.queryParams.params["endCreatedTime"] = this.daterangeCreatedTime[1];
      }
      listYsdz(this.queryParams).then(response => {
        this.ysdzList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    tiao(){
      this.$router.push({path:'/ysd'})
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        reconciliationNo: null,
        customer: null,
        settlementStatus: null,
        totalOrderQuantity: null,
        totalGoodsQuantity: null,
        totalGoodsVolume: null,
        totalGoodsWeight: null,
        totalReceivableAmount: null,
        totalReceivedAmount: null,
        createdBy: null,
        createdTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreatedTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加应收对账单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getYsdz(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改应收对账单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateYsdz(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addYsdz(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除应收对账单编号为"' + ids + '"的数据项？').then(function() {
        return delYsdz(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('ysdz/ysdz/export', {
        ...this.queryParams
      }, `ysdz_${new Date().getTime()}.xlsx`)
    },
    handlePrint() {
      // 调用 window.print() 方法进行打印
      window.print();
    },
    jie(){
      this.form={};
      if(this.ids.length<1){
        this.$message.error("请选着一条数据")
      }else{
        if(this.ids.length>1){
          this.$message.error("只能选择一条数据！")
        }else{
          this.getList();
          this.dialogVisible = true;
          const id=this.ids;
          getYsdz(id).then(response => {
              this.form=response.data;
          })
        }
      }


    },
    bao(){
      this.form.settlementStatus=1;
      this.form.totalReceivedAmount=this.tota;
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateYsdz(this.form).then(response => {
              this.dialogVisible= false;
              this.$modal.msgSuccess("结算成功");
              this.getList();
            });
          }
        }
      });

    },
  }
};
</script>
